import { deleteLibrary, getLibrary, libraryList } from "@/api/service/library/library";
import { librarySizeList } from "@/api/service/library/size";
import { LibrarySize } from "@/api/service/library/types";
import { libraryForm, showLibraryForm } from "./form";
import { libraryQuery, librarySizeData, libraryTable } from "./table";

export const listLibrary = async () => {
  libraryTable.value.loading = true;
  const data = await libraryList(libraryQuery.value);
  libraryTable.value.data = data.rows;
  libraryTable.value.loading = false;
  libraryQuery.value.total = data.total;
};
export const listLibrarySize = async () => {
  const data = await librarySizeList({
    pageNum: 1,
    pageSize: 30
  });
  librarySizeData.value = data.rows.map((e: LibrarySize) => {
    return {
      label: e.sizeDesc,
      value: e.sizeId
    };
  });
};
export const createLibrary = () => {
  showLibraryForm.value = true;
};
export const editLibrary = async (id: string) => {
  const data = await getLibrary(id);
  libraryForm.value = data.data;
  showLibraryForm.value = true;
};
export const delLibrary = async (id: string) => {
  await deleteLibrary([id]);
  listLibrary();
};
